package map.test;

import java.util.*;
import java.util.function.BiConsumer;

/*
定义Map集合,键表示省份，值表示多个市。
 */
public class MapTest2 {
    public static void main(String[] args) {
        HashMap<String, List<String>> hm = new HashMap<>();
        ArrayList<String> list1 = new ArrayList<>();
        ArrayList<String> list2 = new ArrayList<>();
        ArrayList<String> list3 = new ArrayList<>();
        Collections.addAll(list1,"南京市","扬州市","苏州市");
        Collections.addAll(list2,"郑州市","洛阳市","开封市");
        Collections.addAll(list3,"合肥市","蚌埠市","芜湖市");
        hm.put("江苏省",list1);
        hm.put("河南省",list2);
        hm.put("安徽省",list3);

        Set<Map.Entry<String, List<String>>> entries = hm.entrySet();
        for (Map.Entry<String, List<String>> entry : entries) {
            //省份名
            String key = entry.getKey();
            System.out.print(key+"=");
            //市名称
            List<String> list= entry.getValue();
            for (int i = 0; i < list.size()-1; i++) {
                System.out.print(list.get(i)+",");
            }
            System.out.println(list.get(list.size()-1));
        }
    }
}
